<!--
  Copyright (c) 2006-2013, JGraph Ltd
  
  Stencils example for mxGraph. This example demonstrates using
  an XML file to define new stencils to be used as shapes. See
  docs/stencils.xsd for the XML schema file.
-->
<html>
<head>
	<title>Stencils example for mxGraph</title>

	<!-- Sets the basepath for the library if not in same directory -->
	<script type="text/javascript">
		mxBasePath = '../../../javascript/src';
	</script>

	<!-- Loads and initializes the library -->
	<script type="text/javascript" src="../../../javascript/src/js/mxClient.js"></script>

	<!-- Example code -->
	<script type="text/javascript">
		// Program starts here. Creates a sample graph in the
		// DOM node with the specified ID. This function is invoked
		// from the onLoad event handler of the document (see below).
		function main(container)
		{
			// Checks if the browser is supported
			if (!mxClient.isBrowserSupported())
			{
				// Displays an error message if the browser is not supported.
				mxUtils.error('Browser is not supported!', 200, false);
			}
			else
			{
				// Enables crisp rendering of rectangles in SVG
				//mxRectangleShape.prototype.crisp = true;
				
				// Sets the global shadow color
				mxConstants.SHADOWCOLOR = '#C0C0C0';
				mxConstants.SHADOW_OPACITY = 0.5;
				mxConstants.SHADOW_OFFSET_X = 4;
				mxConstants.SHADOW_OFFSET_Y = 4;

				// Creates the graph inside the given container
				var graph = new mxGraph(container);
				graph.setConnectable(true);
				
				// Changes default styles
				var style = graph.getStylesheet().getDefaultVertexStyle();
				delete style[mxConstants.STYLE_FILLCOLOR];

				// Gets the default parent for inserting new cells. This
				// is normally the first child of the root (ie. layer 0).
				var parent = graph.getDefaultParent();
				
				var styleInput = document.createElement('input');
				styleInput.setAttribute('type', 'text');
				styleInput.setAttribute('size', '68');
				styleInput.value = 'shape=timerIntermediate;gradientColor=#00CCFF;fillColor=#99CCFF;strokeWidth=5;shadow=1';
				
				// Adds cells to the model in a single step
				var v1;
				graph.getModel().beginUpdate();
				try
				{
					v1 = graph.insertVertex(parent, null, '', 20, 20, 360, 360, styleInput.value);
				}
				finally
				{
					// Updates the display
					graph.getModel().endUpdate();
				}
				
				var input = document.getElementById('input');
				
				function refresh()
				{
					var doc = mxUtils.parseXml(input.value);
					var shape = doc.documentElement.firstChild;
					
					while (shape != null)
					{
						if (shape.nodeType == mxConstants.NODETYPE_ELEMENT)
						{
							mxStencilRegistry.addStencil(shape.getAttribute('name'), new mxStencil(shape));
						}
						
						shape = shape.nextSibling;
					}
					
					v1.style = styleInput.value;
					graph.refresh();
				}
				
				refresh();
				
				document.body.appendChild(styleInput);
				mxUtils.br(document.body);
				
				document.body.appendChild(mxUtils.button('Refresh', function()
				{
					refresh();
				}));

				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));

				document.body.appendChild(mxUtils.button('FlipH', function()
				{
					graph.toggleCellStyles(mxConstants.STYLE_FLIPH, null, [v1]);
				}));
				
				document.body.appendChild(mxUtils.button('FlipV', function()
				{
					graph.toggleCellStyles(mxConstants.STYLE_FLIPV, null, [v1]);
				}));

				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));
				document.body.appendChild(document.createTextNode('\u00a0'));

				document.body.appendChild(mxUtils.button('North', function()
				{
					graph.setCellStyles(mxConstants.STYLE_DIRECTION, 'north', [v1]);
				}));
				
				document.body.appendChild(mxUtils.button('East', function()
				{
					graph.setCellStyles(mxConstants.STYLE_DIRECTION, 'east', [v1]);
				}));

				document.body.appendChild(mxUtils.button('South', function()
				{
					graph.setCellStyles(mxConstants.STYLE_DIRECTION, 'south', [v1]);
				}));
				
				document.body.appendChild(mxUtils.button('West', function()
				{
					graph.setCellStyles(mxConstants.STYLE_DIRECTION, 'west', [v1]);
				}));
			}
		};
	</script>
</head>

<!-- Page passes the container for the graph to the program -->
<body onload="main(document.getElementById('graphContainer'))">
	<textarea name="textarea"  cols="72" rows="32" style="float:left;margin-right:20px;" id="input"><shapes>
<shape name="or" aspect="variable" strokewidth="inherit">
	<background>
		<path>
			<move x="0" y="0"/>
			<quad x1="100" y1="0" x2="100" y2="50"/>
			<quad x1="100" y1="100" x2="0" y2="100"/>
			<close/>
		</path>
	</background>
	<foreground>
		<fillstroke/>
		<fontcolor color="#000000"/>
		<text str="Label1" x="0" y="0" align="left"/>
		<text str="Label2" x="50" y="50" align="center"/>
		<fontcolor color="#ff0000"/>
		<fontfamily family="Times"/>
		<text x="100" y="100" align="right"><![CDATA[
			function(state)
			{
				return state.cell.value;
			}
		]]></text>
	</foreground>
</shape>
<shape name="xor" aspect="fixed" strokewidth="inherit">
	<background>
		<path>
			<move x="0" y="0"/>
			<quad x1="100" y1="0" x2="100" y2="50"/>
			<quad x1="100" y1="100" x2="0" y2="100"/>
			<quad x1="50" y1="50" x2="0" y2="0"/>
			<close/>
		</path>
	</background>
	<foreground>
		<fillstroke/>
		<image src="bell.png" x="30" y="30" w="40" h="40" flipH="1"/>
		<fontcolor color="#ffffff"/>
		<fontstyle style="1"/>
		<text str="Oben" x="14" y="6" align="left" valign="top"/>
		<text str="Unten" x="14" y="94" align="left" valign="bottom"/>
	</foreground>
</shape>
<shape name="and" aspect="fixed" w="50">
	<background>
		<linejoin join="round"/>
		<path>
			<move x="0" y="0"/>
			<line x="50" y="50"/>
			<line x="0" y="100"/>
			<close/>
		</path>
	</background>
	<foreground>
		<fillstroke/>
	</foreground>
</shape>
<shape name="gate" aspect="fixed">
	<connections>
		<constraint x="0.1" y="0.1" perimeter="0"/>
		<constraint x="0.1" y="0.9" perimeter="0"/>
		<constraint x="0.9" y="0.5" perimeter="0"/>
		<constraint x="0.9" y="0.7" perimeter="0"/>
	</connections>
	<foreground>
		<rect x="0" y="0" w="20" h="20" crisp="1"/>
		<fillstroke/>
		<rect x="0" y="80" w="20" h="20" crisp="1"/>
		<fillstroke/>
		<rect x="80" y="40" w="20" h="20" crisp="1"/>
		<fillstroke/>
		<roundrect x="80" y="60" w="20" h="20" crisp="1"/>
		<fillstroke/>
		<path crisp="1">
			<move x="20" y="10"/>
			<line x="90" y="10"/>
			<line x="90" y="40"/>
			<move x="20" y="90"/>
			<line x="50" y="90"/>
			<line x="50" y="70"/>
			<line x="80" y="70"/>
		</path>
		<stroke/>
	</foreground>
</shape>
<shape name="cross" aspect="fixed">
	<foreground>
		<strokecolor color="#000000"/>
		<strokewidth width="6"/>
		<linecap cap="round"/>
		<path crisp="0">
			<move x="25" y="25"/>
			<line x="75" y="75"/>
		</path>
		<stroke/>
		<path>
			<move x="75" y="25"/>
			<line x="25" y="75"/>
		</path>
		<stroke/>
	</foreground>
</shape>
<shape name="cancel_end" aspect="fixed">
	<foreground>
		<strokecolor color="#000000"/>
		<strokewidth width="8"/>
		<save/>
		<ellipse x="0" y="0" w="100" h="100"/>
		<stroke/>
		<restore/>
		<include-shape name="cross" x="5" y="5" w="90" h="90"/>
	</foreground>
</shape>
<!-- Timer Intermediate -->
<shape name="timer" aspect="fixed">
	<foreground>
        <ellipse x="10" y="10" w="80" h="80"/>
   		<stroke/>
   		<path>
   			<move x="10" y="50"/>
   			<line x="16" y="50"/>
  			<move x="50" y="10"/>
  			<line x="50" y="16"/>
  			<move x="29" y="16"/>
  			<line x="32" y="21"/>
  			<move x="71" y="16"/>
  			<line x="68" y="21"/>
  			<move x="16" y="29"/>
  			<line x="21" y="32"/>
  			<move x="16" y="71"/>
  			<line x="21" y="68"/>
   			<move x="90" y="50"/>
   			<line x="84" y="50"/>
  			<move x="50" y="90"/>
  			<line x="50" y="84"/>
  			<move x="71" y="84"/>
  			<line x="68" y="79"/>
  			<move x="29" y="84"/>
  			<line x="32" y="79"/>
  			<move x="84" y="71"/>
  			<line x="79" y="68"/>
  			<move x="84" y="29"/>
  			<line x="79" y="32"/>
  			<move x="50" y="50"/>
  			<line x="52" y="17"/>
  			<move x="50" y="50"/>
  			<line x="70" y="50"/>
   		</path>
   		<stroke/>
	</foreground>
</shape>
<!-- Timer Start -->
<shape name="timerStart" aspect="fixed" strokewidth="1.5">
	<background>
		<ellipse x="0" y="0" w="100" h="100"/>
	</background>
	<foreground>
   		<fillstroke/>
   		<include-shape name="timer" x="0" y="0" w="100" h="100"/>
	</foreground>
</shape>
<!-- Timer Intermediate -->
<shape name="timerIntermediate" aspect="fixed">
	<background>
		<ellipse x="0" y="0" w="100" h="100"/>
	</background>
	<foreground>
   		<fillstroke/>
   		<ellipse x="3" y="3" w="94" h="94"/>
		<stroke/>
		<include-shape name="timer" x="0" y="0" w="100" h="100"/>
	</foreground>
</shape>
<!-- Kaizen Lightening Burst -->
<shape name="kaizen">
   <background>
		<rect x="10" y="40" w="80" h="20"/>   
   </background>
   <foreground>
   		<fillstroke/>
		<path>
			<move x="18" y="28"/>
			<quad x1="26" y1="41" x2="32" y2="30"/>
			<quad x1="38" y1="39" x2="44" y2="30"/>
			<quad x1="50" y1="42" x2="56" y2="28"/>
			<quad x1="64" y1="38" x2="72" y2="30"/>
			<quad x1="79" y1="42" x2="86" y2="32"/>
			<quad x1="85" y1="40" x2="98" y2="36"/>
			<quad x1="91" y1="47" x2="100" y2="50"/>
			<quad x1="90" y1="55" x2="98" y2="64"/>
			<quad x1="88" y1="58" x2="90" y2="70"/>
			<quad x1="82" y1="59" x2="76" y2="70"/>
			<quad x1="71" y1="60" x2="64" y2="72"/>
			<quad x1="54" y1="56" x2="46" y2="70"/>
			<quad x1="41" y1="58" x2="34" y2="72"/>
			<quad x1="28" y1="59" x2="20" y2="74"/>
			<quad x1="22" y1="61" x2="8" y2="68"/>
			<quad x1="11" y1="59" x2="4" y2="62"/>
			<quad x1="11" y1="54" x2="0" y2="52"/>
			<quad x1="9" y1="43" x2="2" y2="40"/>
			<quad x1="9" y1="37" x2="6" y2="32"/>
			<quad x1="16" y1="42" x2="18" y2="28"/>
		</path>
		<stroke/>
   </foreground>
</shape>
<!-- Electronics - Transitors - MOSFET_P_CH_DEP -->
<shape name="MOSFET_P_CH_DEP" aspect="fixed">
	<connections>
		<constraint x="0.8" y="0" perimeter="0"/>
		<constraint x="0.8" y="1" perimeter="0"/>
		<constraint x="0.1" y="0.5" perimeter="0"/>
	</connections>
	<foreground>
		<strokewidth width = "4"/>
  		<path crisp="1">
  			<move x="10" y="50"/>
  			<line x="40" y="50"/>
  			<move x="40" y="20"/>
  			<line x="40" y="80"/>
  			<move x="50" y="10"/>
  			<line x="50" y="90"/>
  			<move x="50" y="20"/>
  			<line x="80" y="20"/>
  			<line x="80" y="0"/>
  			<move x="50" y="50"/>
  			<line x="80" y="50"/>
  			<line x="80" y="100"/>
  			<move x="50" y="80"/>
  			<line x="80" y="80"/>
  		</path>
  		<stroke/>
  		<path>
  			<move x="80" y="50"/>
  			<line x="72" y="46"/>
  			<line x="72" y="54"/>
  			<line x="80" y="50"/>
  		</path>
  		<fillstroke/>
  		<ellipse x="78" y="78" w="4" h="4"/>
  		<fillstroke/>
	</foreground>
</shape>
</shapes></textarea> 
	<div id="graphContainer"
		style="overflow:hidden;width:401px;height:401px;background:url('http://www.jgraph.com/demo/mxgraph/editors/images/grid.gif');cursor:default;">
	</div>
</body>
</html>
